<?php
//add dragon.hu 2015.6.24 servergolddata

defined('BASEPATH') or die('forbidden');

class Servergolddata_Controller extends Controller
{
	private $conn;
	private $areanum;
	private $areaList;
	
	function _init()
	{
		check_level(50, segment(0), segment(1));
		set_time_limit(0);
		
		$this->areanum = $_SESSION['area_selected_id'];
		if ($this->areanum == '')
		{
			echo "<script>alert('".translate('C_SELECT_AREA_TEXT')."');</script>";
			return;
		}
		$this->areaList = get_area_list_option();
		
		$this->conn = getTmpDbConnect(PLATFORM_ALL, 'all', $this->areanum, DBTYPE_LOG);
	}
	
	function index()
	{
		if(is_submit())
		{
			$startdate = $_POST['row']['starttime'];
			$enddate = $_POST['row']['endtime'];
			$serveridtmp = $_POST['row']['area'];
			$tmp = explode("-", $serveridtmp);
			$serverid = $tmp[0];
			//print_r($startdate);
			//print_r($enddate);
			//print_r($serverid);
			//exit(0);
			
		}else
		{
			//$startdate = date("Y-m-d");
			//$enddate = date("Y-m-d", strtotime("1 day"));
			$startdate = date("Y-m-d", strtotime("-7 day"));
			$enddate = date("Y-m-d");
			$serverid = $this->areanum;
			//print_r($startdate);
			//print_r($enddate);
			//exit(0);
		}
		if (empty($this->areanum) || empty($this->conn)){return;}
		$sql = "SELECT * FROM silverproduce WHERE server_id = $serverid AND operation_time BETWEEN '$startdate' AND '$enddate' order by operation_time asc ";
		//print_r($sql); 
		//exit(0);
		$goldgraph = array();
		$this->conn->query($sql);
		while($n = $this->conn->get_array('default'))
		{
			$time = date($n['operation_time']);
			$date = date("Y-m-d", strtotime($time));
			$goldgraph[$date]['silver_keepnum'] += $n['silver_number'];
			$n['silver_number'] >= 0 ? ($goldgraph[$date]['silver_addnum'] += $n['silver_number']) : ($goldgraph[$date]['silver_expensenum'] += $n['silver_number']);
			
		}
		
		$this->view->assign('startdate', $startdate);
		$this->view->assign('enddate', $enddate);
		$this->view->assign('areaList', $this->areaList);
		$this->view->assign('goldgraph', $goldgraph);
		
		
		
		$this->view->display("message/servergolddata/index");
	}
	
	
}









?>